# 通过User-Agent伪装浏览器
import urllib.request as request
import urllib
from util import logging_util

headers=("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36")
url="https://blog.csdn.net/daichuanya/article/details/100131199"
# 添加报头信息
opener=urllib.request.build_opener() # urlOpen()不能添加报头
opener.addheaders=[headers]
data=opener.open(url).read()

logging_util.print_log("test")
with open("../files/新浪新闻/爬csdn.html", "wb") as fh:
   fh.write(data)

